<?php
class ControllerPost_commet { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newPostcommet();
                break;
            
            case "list":
                $this->listPostcommet();
                break;
            
            case "save":
                $this->savePostcommet();
                break;

            case "edit":
                $this->editPostcommet();
                break;
            
            case "update":
                $this->updatePostcommet();
                break;
            
            case "del":
                $this->deletePostcommet();
                break;
            
            case "combo":
                return $this->comboPostcommet();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newPostcommet(){
        include_once "vista/vista.post_commet.php";
        form_post_commet();
    }    
    

    function savePostcommet(){
        include_once "modelo/modelo.post_commet.php";
        
        $p = new post_commet();
        $p->set_pc_id($_REQUEST["pc_id"]); 
        $p->set_pc_p_id($_REQUEST["pc_p_id"]); 
        $p->set_pc_desc($_REQUEST["pc_desc"]); 
        $p->set_pc_date($_REQUEST["pc_date"]); 
        $p->set_pc_u_id($_REQUEST["pc_u_id"]); 
        $p->set_pc_status($_REQUEST["pc_status"]); 

        
        if($p->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listPostcommet($msj);
        
    }    
    
    function editPostcommet(){
        include_once 'modelo/modelo.post_commet.php';
        include_once 'vista/vista.post_commet.php';
        
        $p = new post_commet();
        $p->setpc_id($_REQUEST["pc_id"]); 
        
        $p->getData();
        
        form_post_commet($p);
        
    }    
    
    function deletePostcommet(){
        include_once 'modelo/modelo.post_commet.php';
        
        $p = new post_commet();
        $p->setpc_id($_REQUEST["pc_id"]); 
        
        if($p->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listPostcommet($msj);
    }

    
    function updatePostcommet(){
        include_once 'modelo/modelo.post_commet.php';
        
        $p = new post_commet();
        $p->set_pc_id($_REQUEST["pc_id"]); 
        $p->set_pc_p_id($_REQUEST["pc_p_id"]); 
        $p->set_pc_desc($_REQUEST["pc_desc"]); 
        $p->set_pc_date($_REQUEST["pc_date"]); 
        $p->set_pc_u_id($_REQUEST["pc_u_id"]); 
        $p->set_pc_status($_REQUEST["pc_status"]); 

        if($p->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listPostcommet($msj);
    }

    
    function listPostcommet($msj=false){
        include_once 'modelo/modelo.post_commet.php';
        include_once 'vista/vista.post_commet.php';
        
        $p = new post_commet();

        $p->setpc_id($_REQUEST["pc_id"]); 
        $p->getData();
        
        $dataTotal = $p->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $p->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_post_commet($data, $msj, $dataTotal);

    }

}